<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox>
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" style="width: 100%">
          <!-- <el-select
            class="selectBhz"
            v-model="getList.stationId"
            placeholder="所有拌和站"
            @change="selectBhz"
            style="width: 160px"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select> -->
          <!-- <el-select
            class="selectBhz"
            v-model="getList.machineId"
            placeholder="所有拌和机"
            @change="yj_searchForm(getList)"
            style="width: 160px"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select> -->
          <el-select
            class="selectBhz"
            v-model="getList.fConstructtypeid"
            placeholder="施工类型"
            @change="yj_searchForm(getList)"
            style="width: 160px"
          >
            <el-option
              v-for="v in construction"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-button
            type="primary"
            icon="el-icon-search"
            size="small"
            @click="yj_searchForm(getList)"
            >查询
          </el-button>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @change="yj_searchForm(getList)"
            >
            </el-button>
            <el-button
              type="primary"
              v-if="yj_view"
              icon="el-icon-search"
              size="small"
              @click="editText(fId)"
              >查看
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="small"
              @click="Print()"
              >打印
            </el-button>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>

      <!--班组首件信息弹框-->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="baseTitle">班组首件信息</div>
              <div class="publicForm" style="height: 300px">
                <div class="publicFormBox">
                  <publicForm
                    ref="publicForm0"
                    lableWidth="160px"
                    :formObj="FromShowTop"
                    :formData="formData"
                    :timestamp="formData.fDirectorreportfile"
                    :fileList="fSourcefileList"
                  >
                  </publicForm>
                </div>
                <div class="publicFormBox">
                  <publicForm
                    ref="publicForm1"
                    lableWidth="160px"
                    :formObj="FromShowBottom"
                    :formData="formData"
                    :timestamp="formData.fQualityimagefile"
                    :fileList="fSourcefileList1"
                  >
                  </publicForm>
                </div>
              </div>

              <div class="baseTitle">签认</div>
              <div class="publicForm" style="height: 80px">
                <publicForm
                  ref="publicForm2"
                  lableWidth="160px"
                  :formObj="FromShow1"
                  :formData="formData"
                >
                </publicForm>
              </div>

              <div style="height: 50px"></div>
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import tree from "@/components/QualityGridManage/tree"; //左侧机构树
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项

import {
  // getUserCompanyTreeList, //左侧机构树接口
  getXmCompanyTreeList, //左侧机构树接口--不带分子公司
  getGroupTeamPageLists, //主页面列表接口
  // getStationmachineList, //拌合站列表
  // getMachineListByStationId, //拌合机
  getGroupTeamByFid, //详情
} from "@/api/request.js";

export default {
  name: "groupClass",
  data() {
    return {
      name: "groupClass", //按钮配置页面代号
      yj_view: null,
      construction: formJs.construction, //下拉框施工类型
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页

      // 列表
      getList: {
        fCompanyid: "", // 左侧选中组织机构id
        fConstructtypeid: "", //查询条件 施工类型id 可不传
        page: 1, //页码
        pageSize: 20, //每页条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "", // 0代办 1已办 不传或传空 表示列表页查询
        sublevel: 1,
      },
      fId: null, //当前行数据fId
      row: { fstatus: "" }, //选中行
      loading: false, //列表转载
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      // 列表

      // 弹框·
      timeYMD: null, //当前日期
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      FromShowTop: formJs.FromShowLookTop, //信息编辑配置参数
      FromShowBottom: formJs.FromShowLookBottom, //信息编辑配置参数
      FromShow1: formJs.FromShowLook1, //信息编辑配置参数
      formData: formJs.formData,
      recordfiles: [], //删除文件
      recordfiles1: [], //删除文件
      fSourcefileList: [],
      fSourcefileList1: [],
      saveData: formJs.saveData,
      getUserInitialList: [], //人员列表初始值
      // 弹框

      // 机构树
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      treeText: {
        companyId: null,
        userId: null,
      },
      checkData: [], //树状图默认选中id
      // 机构树
      userInfo: {}, //登录用户
    };
  },
  components: {
    elBreadcrumb,
    tree, //左侧组织机构数
    TableData, //主页面列表
    publicForm, //弹框表格
    Pagination, //分页
  },
  mounted() {
    this.getList.modelType = "2";
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    // if (JSON.parse(sessionStorage.getItem("scene_getList"))) {
    //   var getListStorage = JSON.parse(sessionStorage.getItem("scene_getList"));
    //   this.getList.fCompanyid = getListStorage.fCompanyid;
    // }

    if (JSON.parse(sessionStorage.getItem("Quality_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("Quality_treeCheck"));
      this.checkData = [id.fCompanyid];
    }

    this.getTree();
    this.btnRole(this.name);
  },
  methods: {
    //查看下级
    see() {
      if (this.checked == true) {
        this.getList.sublevel = 1;
      } else {
        this.getList.sublevel = 0;
      }
      this.yj_searchForm(this.getList);
    },
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });

        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_view = true;
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText.companyId = this.userInfo.companyId;
      this.treeText.userId = this.userInfo.userId;
      // getUserCompanyTreeList(this.treeText)
      getXmCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            console.log(888, this.treeData);
            if (
              this.treeData[0].children == undefined &&
              this.treeData.length <= 1
            ) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("Quality_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
              this.checkData[0] = this.treeData[0].fCompanyid;
            }
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      var sublevel = null;
      if (this.checked == true) {
        sublevel = 1;
      } else {
        sublevel = 0;
      }
      this.getList = {
        fCompanyid: data.fCompanyid, // 左侧选中组织机构id
        fConstructtypeid: "", //查询条件 施工类型id 可不传
        page: 1, //页码
        pageSize: 20, //每页条数
        userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
        modelType: 2, // 0代办 1已办 不传或传空 表示列表页查询
        sublevel: sublevel,
      };
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      if (id.fConstructtypeid == "==施工类型==") {
        id.fConstructtypeid = "";
      }
      id.userId = this.userInfo.userId;
      this.row = { fstatus: "" }; //选中行
      this.loading = true;
      // window.sessionStorage.setItem("scene_getList", JSON.stringify(id));
      getGroupTeamPageLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 点击查看
    yj_viewForm(row, label) {
      this.row = row;
      console.log("row", this.row);
      this.fId = row.fId;
      if (label == "班组施工类型") {
        this.editText(this.fId);
      }
    },
    // 查看
    editText(id) {
      this.dialogTitle = "查看";
      this.btnShow = false;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getGroupTeamByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog = false;
              this.formData = res.data.yjQmpMsGroupteamInformation;
              this.fSourcefileList = res.data.fDirectorreportfilelist; //首件工程总结报告
              this.fSourcefileList1 = res.data.fQualityimagefilelist; //首件工程相关影像
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },

    getDate() {},
    // 获取页面容器高度
    getHeight() {
      // var h = document.documentElement.clientHeight; //获取页面可见高度
    },

    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
/* 弹框 */
.publicForm {
  display: flex;
}
.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 163px !important;
}
.publicFormBox {
  width: 50%;
  height: 100%;
}
/* 弹框 */
</style>
